<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>深拷贝</title>
</head>

<body>
    <script>

        function deepCopy(obj) {
            // 日期
            if (obj instanceof Date) {
                return new Date(obj)
            }
            // 正则
            if (obj instanceof RegExp) {
                return new RegExp(obj)
            }
            let result = null;
            // 数组
            if (obj instanceof Array) {
                result = [];
                // 对象
            } else if (obj instanceof Object) {
                result = {};
            }
            for (let key in obj) {
                if (typeof obj[key] == 'object' && obj[key]) {
                    result[key] = deepCopy(obj[key]);
                } else {
                    result[key] = obj[key];
                }
            }

            return result
        }

    </script>
</body>

</html>